﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GraphicUserInterface.NewAccount;
using DataTransferObjects;
using GraphicUserInterface.MainForm.NewAccount;
using GraphicUserInterface.MainForm.Export_ImportKey;
using Business;
using GraphicUserInterface.MainForm.Encrypt_Decrypt;
using GraphicUserInterface.MainForm.Sign_VerifyDigitalSignature;

namespace GraphicUserInterface.MainForm
{
    public partial class frMainForm : Form
    {
        AccountInforDTO accountInfor = new AccountInforDTO();//Lưu thông tin về tài khoản hiện tại
        KeyInforDTO keyInfor = new KeyInforDTO();//Lưu thông tin về cặp khóa hiện tại

        //delegate để nhận dữ liệu từ nơi khác
        public void receiveAccInfor(AccountInforDTO accountInfor)
        {
            this.accountInfor.iUserID = accountInfor.iUserID;
            this.accountInfor.strName = accountInfor.strName;
            this.accountInfor.birthday = accountInfor.birthday;
            this.accountInfor.phoneNumber = accountInfor.phoneNumber;
            this.accountInfor.address = accountInfor.address;
            this.accountInfor.email = accountInfor.email;
            this.updateAccountInforOnForm();
        }

        public frMainForm(string iUserEmail)
        {
            InitializeComponent();
            this.accountInfor = AccountBUS.getAccInforFromDB(iUserEmail);
        }

        private void btCreateAcc_Click(object sender, EventArgs e)
        {
            frNewAccount newAccForm = new frNewAccount();
            newAccForm.Owner = this;
            newAccForm.Show();
            this.Hide();
        }

        private void btChangeAccInfor_Click(object sender, EventArgs e)
        {
            frChangeAccount changeAccForm = new frChangeAccount(this.accountInfor.iUserID);
            frCheckPassphraseValid checkPassphraseValidForm = new frCheckPassphraseValid(accountInfor.iUserID, changeAccForm);
            checkPassphraseValidForm.Owner = this;
            checkPassphraseValidForm.Show();
            this.Hide();
        }



        private void btChangeAcc_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn chắn chắn muốn đăng xuất khỏi chương trình?", "Đăng xuất?", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                this.Owner.Show();
                this.Close();
            }
        }

        private void btExitProgram_Click(object sender, EventArgs e)
        {
            this.Owner.Close();
            this.Close();
        }

        private void btEx_ImportAcc_KeyInfor_Click(object sender, EventArgs e)
        {
            frExport_ImportKey frImportExportKey = new frExport_ImportKey(this.accountInfor.iUserID);
            frImportExportKey.Owner = this;
            frImportExportKey.Show();
            this.Hide();
        }

        private void updateAccountInforOnForm()
        {
            string strMessage = "Thông tin sơ lược tài khoản:";
            strMessage = strMessage + "\r\n- Email:\t" + accountInfor.email;
            strMessage = strMessage + "\r\n- Tên:\t" + accountInfor.strName;
            strMessage = strMessage + "\r\n- Địa chỉ:\t" + accountInfor.address;
            tbInfor.Text = strMessage;
        }

        private void frMainForm_Load(object sender, EventArgs e)
        {
            this.updateAccountInforOnForm();
        }

        private void btEncrypt_Decrypt_Click(object sender, EventArgs e)
        {
            frEncryptDecryptData frEncryptDecrypt = new frEncryptDecryptData(this.accountInfor.iUserID);
            frEncryptDecrypt.Owner = this;
            frEncryptDecrypt.Show();
            this.Hide();
        }

        private void btVerifyDigitalSignal_Click(object sender, EventArgs e)
        {
            frDigitalSignature digitalSignature = new frDigitalSignature(this.accountInfor.iUserID);
            digitalSignature.Owner = this;
            digitalSignature.Show();
            this.Hide();
        }


    }
}
